<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .top {
            width: 600px;
            height: 100px;
            margin: 10px auto;
        }

        input {
            width: 200px;
            height: 20px;
        }

        span {
            display: inline-block;
            margin-left: 10px;
        }

        button {
            margin-top: 5px;
        }

        p {
            margin-top: 5px;
        }
    </style>
</head>

<body>
    <div class="top">
        <input type="text"><span>输入数字求和，数字之间用半角","号分隔</span><br>
        <button>求和</button>
        <p></p>
    </div>
</body>
<script>
    var inp = document.getElementsByTagName('input')[0]
    var btn = document.getElementsByTagName('button')[0]
    var pp = document.getElementsByTagName('p')[0]
    btn.onclick = function () {
        let arr = inp.value.split(',')
        let sum = 0
        for (var i in arr) {
            sum += arr[i] * 1
        }
        console.log(sum);
        pp.innerHTML = sum
    }
</script>

</html>